package com.flyxteam.commons.httpclient;

/**
 * <b>功能：</b>HttpClient操作的连接工厂类，提供创建会话连接等<br>
 * <b>Copyright TCSL</b>
 * <ul>
 * <li>版本&nbsp;&nbsp;&nbsp;&nbsp;修改日期&nbsp;&nbsp;&nbsp;&nbsp;部　　门&nbsp;&nbsp;&nbsp;&nbsp;作　者&nbsp;&nbsp;&nbsp;&nbsp;变更内容</li>
 * <hr>
 * <li>v1.0&nbsp;&nbsp;&nbsp;&nbsp;20141216&nbsp;&nbsp;技术中心&nbsp;&nbsp;&nbsp;&nbsp;史盟&nbsp;&nbsp;&nbsp;&nbsp;创建类</li>
 * </ul>
 */
public class HttpClientSessionFactory {

	private HttpClientSessionFactory() {}
	
	/**
	 * <b>功能描述：</b>建立HttpClient操作的连接会话<br>
	 * <b>修订记录：</b><br>
	 * <li>20141101&nbsp;&nbsp;|&nbsp;&nbsp;史盟&nbsp;&nbsp;|&nbsp;&nbsp;创建方法</li><br>
	 * 
	 * @param config {charset=字符集(String), connect_timeout=连接超时(int, 毫秒), socket_timeout=通讯超时(int, 毫秒)}
	 * @return
	 */
	public static HttpClientSession createSession(HttpClientConfig config) {
		HttpClientSessionImpl ins = new HttpClientSessionImpl();
		ins.setHttpClient(HttpConnectionManager.getHttpClient());
		if (config == null) {
			config = new HttpClientConfig();
		}
		ins.setConfig(config);
		return ins;
	}

	/**
	 * <b>功能描述：</b>建立HttpClient操作的连接会话<br>
	 * <b>修订记录：</b><br>
	 * <li>20150105&nbsp;&nbsp;|&nbsp;&nbsp;史　盟&nbsp;&nbsp;|&nbsp;&nbsp;创建方法</li><br>
	 * @param connectTimeout 连接超时
	 * @param socketTimeout 通信超时
	 * @param charset 字符集编码
	 * @param readBufferSize 读取缓存
	 * @return
	 */
	public static HttpClientSession createSession(Integer connectTimeout, Integer socketTimeout, String charset, Integer readBufferSize) {
		HttpClientConfig config = new HttpClientConfig(connectTimeout, socketTimeout, charset, readBufferSize);
		return createSession(config);
	}
	
	/** 
	 * @see #createSession(Integer, Integer, String, Integer)
	 */
	public static HttpClientSession createSession(Integer connectTimeout, Integer socketTimeout, String charset) {
		return createSession(connectTimeout, socketTimeout, charset, null);
	}

	/** 
	 * @see #createSession(Integer, Integer, String, Integer)
	 */
	public static HttpClientSession createSession(Integer connectTimeout, Integer socketTimeout) {
		return createSession(connectTimeout, socketTimeout, null, null);
	}
}
